package controllers

import (
	"encoding/json"
	"github.com/beego/beego/v2/core/logs"
	"github.com/beego/beego/v2/server/web"
	"rate/common/consts"
	"rate/common/res"
	"rate/models"
	"rate/pojo/ao"
	"rate/pojo/entity"
)

type TunnelController struct {
	web.Controller
}

// CreateTunnel 创建隧道
// @router /client [post]
func (req *TunnelController) CreateTunnel() {
	var tunnel ao.TunnelAo
	if err := json.Unmarshal(req.Ctx.Input.RequestBody, &tunnel); err != nil {
		logs.Error("参数获取错误,%s", err.Error())
		res.SystemFail(&req.Controller)
	}
	member := (req.Ctx.Input.GetData("member")).(*entity.Member)
	// 创建客户端
	if err := models.CreateClient(member.Id, tunnel.Area); err != nil {
		res.Fail(&req.Controller, consts.ClientError)
	}
	// 创建隧道

}
